<?
	session_start();
	require_once '../librarys/funs/class_user.php';
    $t= new tin();
	$bien['ten_sp']=$_GET['ten_sp'];
	$bien['ma_sp']=$_GET['ma_sp'];
	$bien['mausac']=$_GET['mausac'];
	$bien['soluong']=$_GET['soluong'];
	$bien['dongia']=$_GET['dongia'];
	$bien['thanhtien']=$_GET['thanhtien'];
	$bien['hoten']=$_GET['hoten'];
	$bien['email']=$_GET['email'];
	$bien['diachi']=$_GET['diachi'];
	$bien['dienthoai']=$_GET['dienthoai'];
	$bien['noidung']=$_GET['noidung'];
	$id=$_GET['id'];
	$soluong=$_GET['soluong'];
	$now = getdate();
	$ngay = $now["year"]."-".$now["mon"]."-".$now["mday"]." ".$now["hours"].":".$now["minutes"].":".$now["seconds"];
	$bien['ngay']=$ngay;
	
	$thongtin=$t->get_by_thutu("thongtin");
	$row_thongtin=mysql_fetch_assoc($thongtin);
    $fromname='Khach hang dat hang';
    $to=$row_thongtin['ten_vi'];
	$tongtien=$t->TongTienGioHang();
    $body="<table width=538 border=1 align=center cellpadding=0 cellspacing=0 id=tbldangky>
                <tr><th>Tên khách hàng</th>
                        <td>".$bien['hoten']."</td>
                </tr>
                <tr><th>Điện thoại</th>
                        <td>".$bien['dienthoai']."</td>
                </tr>
    			<tr><th>Điện thoại</th>
                        <td>".$bien['diachi']."</td>
                </tr>
                </tr>
                <tr><th height='62'>Nội dung</th>
                        <td>".$bien['noidung']."
                </td>
                </tr>
				<tr><th height='62'>Mã sản phẩm</th>
                        <td>".$bien['ma_sp']."
                </td>
                </tr>
				<tr><th height='62'>Tên sản phẩm</th>
                        <td>".$bien['noidung']."
                </td>
                </tr>
				<tr><th height='62'>Màu sắc</th>
                        <td>".$bien['mausac']."
                </td>
                </tr>
                <tr><th height='62'>Đơn giá x Số lượng</th>
					<td>".number_format($bien['dongia'],0,",",".")."x".$bien['soluong']."
                </td>
				<tr><th height='62'>Thành tiền</th>
					<td>".number_format($bien['thanhtien'],0,",",".")."
                </td>
                </table>";
				//echo $to;die;
                $t->send_mail($fromname,$to,$body);

	$bien['thutu']=$t->get_thutu("donhang");
		//print_r($bien);die;
	$res=$t->insertObject1("donhang",$bien);
	
	$sp=$t->get_by_thutu("sanpham",$id);
	$row_sp=mysql_fetch_assoc($sp);
	$bien1['dathang']=$row_sp['dathang']+$soluong;
	$res=$t->updateObject1("sanpham",$bien1,"id='$id'");
	
?>